package com.thinta.wind.ui.home.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.thinta.wind.base.BaseModel
import com.thinta.wind.config.JetPackDMConfig
import com.thinta.wind.entity.HotDataItemBean
import com.thinta.wind.ui.home.repository.HotComRepository
import com.thinta.wind.ui.home.repository.NearByDataSource

class HotComViewModel(private val repository: HotComRepository) : BaseModel() {

    var result : LiveData<PagingData<HotDataItemBean>>? = null

    fun getHotData(catId : String, pageSize : Int, userId : String){
        result = Pager(
            PagingConfig(pageSize = JetPackDMConfig.PAGE_SIZE,
                prefetchDistance = JetPackDMConfig.PAGE_SIZE / 2,
                enablePlaceholders = JetPackDMConfig.ENABLE_PLACEHOLDERS,
                initialLoadSize = JetPackDMConfig.PAGE_SIZE_HINT)
        ){
           NearByDataSource(repository, catId, pageSize, userId)
        }.flow.cachedIn(viewModelScope).asLiveData(viewModelScope.coroutineContext)
    }
}
